/**
 * AddTakenCompanyInfoForm class.
 */
package pits.form;

import java.util.ArrayList;
import java.util.List;
import pits.dto.DepartexpDTO;
import pits.dto.EmployeeDTO;
import javax.portlet.ActionRequest;
import pits.util.Constants;

/**
 * @author ltd
 * 
 */
public class AddTakenCompanyInfoForm {

	private String txtDepartID;
	private String txtStartDate;
	private String txtEndDate;
	private String txtRole;
	private String txtDescription;

	public AddTakenCompanyInfoForm() {

	}

	public String getTxtDepartID() {
		return txtDepartID;
	}

	public void setTxtDepartment(String txtDepartID) {
		this.txtDepartID = txtDepartID;
	}

	public String getTxtStartDate() {
		return txtStartDate;
	}

	public void setTxtStartDate(String txtStartDate) {
		this.txtStartDate = txtStartDate;
	}

	public String getTxtEndDate() {
		return txtEndDate;
	}

	public void setTxtEndDate(String txtEndDate) {
		this.txtEndDate = txtEndDate;
	}

	public String getTxtRole() {
		return txtRole;
	}

	public void setTxtRole(String txtRole) {
		this.txtRole = txtRole;
	}

	public String getTxtDescription() {
		return txtDescription;
	}

	public void setTxtDescription(String txtDescription) {
		this.txtDescription = txtDescription;
	}

	public List<String> validate(EmployeeDTO dtoEmp) {
		List<String> errList = new ArrayList<String>();
		// new pits.util.Logger().write(txtDepartID + " " + txtRole);
		// department
		if (this.txtDepartID.isEmpty()) {
			errList.add("Department must be filled! Add failed!");
		}
		// new pits.util.Logger().write("depart " + this.txtDepartID);
		List<DepartexpDTO> depexps = dtoEmp.getDepartexps();
		for (int i = 0; i < depexps.size(); i++) {
			if (Integer.parseInt(this.txtDepartID) == depexps.get(i).getDepartment().getDepartID()) {
				errList.add("This department already exists in your experiences! Add failed!");
				// new pits.util.Logger().write("err " + errList.get(0));
				break;
			}
		}
		// role
		if (this.txtRole.isEmpty()) {
			errList.add("Role must be filled! Add failed!");
		}
		return errList;
	}

	public void setFields(ActionRequest request) {
		if (request.getParameter("txtDepartment") != null) {
			setTxtDepartment(request.getParameter("txtDepartment"));
		}
		if (request.getParameter("txtStartDate") != null) {
			setTxtStartDate(request.getParameter("txtStartDate"));
		}
		if (request.getParameter("txtEndDate") != null) {
			setTxtEndDate(request.getParameter("txtEndDate"));
		}
		if (request.getParameter("txtRole") != null) {
			setTxtRole(request.getParameter("txtRole"));
		}
		if (request.getParameter("txtDescription") != null) {
			setTxtDescription(request.getParameter("txtDescription"));
		} else {
			setTxtDescription(Constants.BLANK_VALUE);
		}
	}
}
